home *** CD-ROM | disk | FTP | other *** search
- program DockMan;
-
- uses
- System,
- System.ComponentModel,
- System.Drawing,
- System.Windows.Forms;
-
- type
- { .NET to VCL mapping }
- TForm = Form;
- TButton = Button;
- TPanel = Panel;
- TGroupBox = GroupBox;
- TRadioButton = RadioButton;
- TCheckBox = CheckBox;
-
- TContainer = Container;
- TToolTip = ToolTip;
- TPoint = Point;
- TSize = Size;
-
- { Main application form }
- [STAThread]
- TMainForm = class(TForm)
- private
- procedure ApplyChanges;
- procedure InitComponents;
- protected
- procedure CheckBoxClick(Sender: TObject; E: EventArgs);
- procedure RadioButtonClick(Sender: TObject; E: EventArgs);
- published
- Components: TContainer;
- Panel1: TPanel;
- Panel2: TPanel;
- GroupBox1: TGroupBox;
- GroupBox2: TGroupBox;
- ToolTip1: TToolTip;
- btnDemo: TButton;
- rdbSet: TRadioButton;
- rdbNone: TRadioButton;
- rdbTop: TRadioButton;
- rdbLeft: TRadioButton;
- rdbBottom: TRadioButton;
- rdbRight: TRadioButton;
- rdbFill: TRadioButton;
- chkTop: CheckBox;
- chkLeft: CheckBox;
- chkBottom: CheckBox;
- chkRight: CheckBox;
- public
- constructor Create(Owner: TObject);
- destructor Destroy; override;
- end;
-
-
- constructor TMainForm.Create(Owner: TObject);
- begin
- inherited Create;
- InitComponents;
-
- // Wire up event handlers
- rdbRight.Add_Click(RadioButtonClick);
- rdbFill.Add_Click(RadioButtonClick);
- rdbBottom.Add_Click(RadioButtonClick);
- rdbNone.Add_Click(RadioButtonClick);
- rdbLeft.Add_Click(RadioButtonClick);
- chkTop.Add_Click(CheckBoxClick);
- chkLeft.Add_Click(CheckBoxClick);
- chkRight.Add_Click(CheckBoxClick);
- chkBottom.Add_Click(CheckBoxClick);
- rdbTop.Add_Click(RadioButtonClick);
-
- // Complete intialization of the form
- rdbSet:= rdbNone;
-
- ApplyChanges;
- end;
-
- destructor TMainForm.Destroy;
- begin
- if (Components <> nil) then
- Components.Dispose;
- inherited;
- end;
-
- procedure TMainForm.InitComponents;
- begin
- SuspendLayout;
-
- // Initialize components here...
- Components:= TContainer.Create;
- rdbRight:= TRadioButton.Create;
- GroupBox1:= TGroupBox.Create;
- Panel2:= TPanel.Create;
- rdbNone:= TRadioButton.Create;
- GroupBox2:= TGroupBox.Create;
- btnDemo:= TButton.Create;
- rdbSet:= TRadioButton.Create;
- rdbBottom:= TRadioButton.Create;
- chkBottom:= TCheckBox.Create;
- rdbTop:= TRadioButton.Create;
- rdbLeft:= TRadioButton.Create;
- chkLeft:= TCheckBox.Create;
- chkTop:= TCheckBox.Create;
- rdbFill:= TRadioButton.Create;
- chkRight:= TCheckBox.Create;
- Panel1:= TPanel.Create;
-
- //ToolTip1:= TToolTip(Components);
- ToolTip1:= TToolTip.Create;
-
- Text:= 'Docking and Anchoring Example';
- AutoScaleBaseSize:= TSize.Create(5, 13);
- SizeGripStyle:= SizeGripStyle.Show;
- Location:= TPoint.Create(100, 100);
- ClientSize:= TSize.Create(448, 400);
-
- rdbRight.Location:= TPoint.Create(8, 120);
- rdbRight.Size:= TSize.Create(72, 24);
- rdbRight.TabIndex:= 4;
- rdbRight.Text:= '&Right';
-
- GroupBox1.Location:= TPoint.Create(16, 16);
- GroupBox1.Size:= TSize.Create(88, 128);
- GroupBox1.TabIndex:= 0;
- GroupBox1.TabStop:= False;
- GroupBox1.Text:= 'A&nchor';
-
- Panel2.BorderStyle:= BorderStyle.Fixed3D;
- Panel2.Dock:= DockStyle.Left;
- Panel2.Location:= TPoint.Create(325, 0);
- Panel2.Size:= TSize.Create(120, 400);
- Panel2.TabIndex:= 0;
- Panel2.Text:= 'ControlsPanel';
-
- ToolTip1.SetToolTip(panel2, 'Resize the form to see the layout effects.');
-
- rdbNone.Location:= TPoint.Create(8, 24);
- rdbNone.Size:= TSize.Create(72, 24);
- rdbNone.TabIndex:= 5;
- rdbNone.TabStop:= True;
- rdbNone.Text:= '&None';
- rdbNone.Checked:= True;
-
- GroupBox2.Location:= TPoint.Create(16, 152);
- GroupBox2.Size:= TSize.Create(88, 176);
- GroupBox2.TabIndex:= 1;
- GroupBox2.TabStop:= False;
- GroupBox2.Text:= '&Dock';
-
- btnDemo.BackColor:= SystemColors.Control;
- btnDemo.FlatStyle:= FlatStyle.Popup;
- btnDemo.Size:= TSize.Create(120, 24);
- btnDemo.Location:= TPoint.Create(0, 0);
- btnDemo.TabIndex:= 0;
- btnDemo.Anchor:= AnchorStyles.None;
- btnDemo.Text:= 'Demo Button';
-
- ToolTip1.SetToolTip (btnDemo, 'Nothing happens if you click this button.');
-
- rdbSet.Size:= TSize.Create(100, 23);
- rdbSet.TabIndex:= 0;
- rdbSet.Text:= 'rdbSet';
-
- ToolTip1.Active:= True;
-
- rdbBottom.Location:= TPoint.Create(8, 96);
- rdbBottom.Size:= TSize.Create(72, 24);
- rdbBottom.TabIndex:= 1;
- rdbBottom.Text:= '&Bottom';
- chkBottom.Location:= TPoint.Create(8, 72);
- chkBottom.Size:= TSize.Create(72, 24);
- chkBottom.TabIndex:= 3;
- chkBottom.Text:= '&Bottom';
-
- rdbTop.Location:= TPoint.Create(8, 48);
- rdbTop.Size:= TSize.Create(72, 24);
- rdbTop.TabIndex:= 0;
- rdbTop.Text:= '&Top';
-
- rdbLeft.Location:= TPoint.Create(8, 72);
- rdbLeft.Size:= TSize.Create(72, 24);
- rdbLeft.TabIndex:= 3;
- rdbLeft.Text:= '&Left';
- chkLeft.Location:= TPoint.Create(8, 48);
- chkLeft.Size:= TSize.Create(72, 24);
- chkLeft.TabIndex:= 2;
- chkLeft.Text:= '&Left';
-
- chkTop.Location:= TPoint.Create(8, 24);
- chkTop.Size:= TSize.Create(72, 24);
- chkTop.TabIndex:= 0;
- chkTop.Text:= '&Top';
-
- rdbFill.Location:= TPoint.Create(8, 144);
- rdbFill.Size:= TSize.Create(72, 24);
- rdbFill.TabIndex:= 2;
- rdbFill.Text:= '&Fill';
-
- chkRight.Location:= TPoint.Create(8, 96);
- chkRight.Size:= TSize.Create(72, 24);
- chkRight.TabIndex:= 1;
- chkRight.Text:= '&Right';
-
- Panel1.BorderStyle:= BorderStyle.Fixed3D;
- Panel1.BackColor:= Color.Green;
- Panel1.Dock:= DockStyle.Fill;
- Panel1.TabIndex:= 1;
- Panel1.Text:= 'ButtonPanel';
-
- Controls.Add(Panel1);
- Controls.Add(Panel2);
-
- Panel1.Controls.Add(btnDemo);
- Panel2.Controls.Add(GroupBox1);
- Panel2.Controls.Add(GroupBox2);
-
- GroupBox1.Controls.Add(chkRight);
- GroupBox1.Controls.Add(chkBottom);
- GroupBox1.Controls.Add(chkLeft);
- GroupBox1.Controls.Add(chkTop);
-
- GroupBox2.Controls.Add(rdbBottom);
- GroupBox2.Controls.Add(rdbLeft);
- GroupBox2.Controls.Add(rdbNone);
- GroupBox2.Controls.Add(rdbRight);
- GroupBox2.Controls.Add(rdbFill);
- GroupBox2.Controls.Add(rdbTop);
-
- ResumeLayout(False);
- end;
-
- procedure TMainForm.ApplyChanges;
- var
- nSettings: AnchorStyles;
- begin
- //Apply Anchoring Settings - maybe multiple
- nSettings:= AnchorStyles.None;
-
- // Compiler still does not have the notion of sets!!!
- if (chkTop.Checked) then
- nSettings:= AnchorStyles(Integer(nSettings)+ Integer(AnchorStyles.Top));
- if (chkLeft.Checked) then
- nSettings:= AnchorStyles(Integer(nSettings)+ Integer(AnchorStyles.Left));
- if (chkBottom.Checked) then
- nSettings:= AnchorStyles(Integer(nSettings)+ Integer(AnchorStyles.Bottom));
- if (chkRight.Checked) then
- nSettings:= AnchorStyles(Integer(nSettings)+ Integer(AnchorStyles.Right));
-
- btnDemo.Anchor:= nSettings;
-
- //Apply Docking settings - one only
- if (rdbSet = rdbNone) then
- btnDemo.Dock:= DockStyle.None
- else if (rdbSet = rdbTop) then
- btnDemo.Dock:= DockStyle.Top
- else if (rdbSet = rdbLeft) then
- btnDemo.Dock:= DockStyle.Left
- else if (rdbSet = rdbBottom) then
- btnDemo.Dock:= DockStyle.Bottom
- else if (rdbSet = rdbRight) then
- btnDemo.Dock:= DockStyle.Right
- else // The default is: if (rdbSet is rbFill)
- btnDemo.Dock:= DockStyle.Fill;
- end;
-
- procedure TMainForm.CheckBoxClick(Sender: TObject; E: EventArgs);
- begin
- ApplyChanges;
- end;
-
- procedure TMainForm.RadioButtonClick(Sender: TObject; E: EventArgs);
- begin
- rdbSet:= RadioButton(sender);
- ApplyChanges;
- end;
-
-
- var
- F: TMainForm;
- begin
- F:= TMainForm.Create(nil);
- Application.Run(F);
- F.Free;
- end.
-